<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var obj1 = {
                x: {
                    m: 1
                },
                y: undefined,
                z: function add(z1, z2) {
                    return z1 + z2
                },
                d:[3,2,1],
                a: Symbol("foo")
            };
        function deepClone(obj){
            //创建一个新对象
            let result = {}
            let keys = Object.keys(obj),
                key = null,
                temp = null;
            console.log(keys)
            for (let i=0;i<keys.length;i++){
                key = keys[i];
                temp = obj[key];
                //如果字段的值也是一个对象则递归操作
                if (temp && typeof temp === 'object'){
                    result[key] = deepClone(temp)
                } else {
                    //否则直接赋值给新对象
                    result[key] = temp
                }
            }
            return result
        }
        var obj2 = deepClone(obj1);
        obj2.x.m = 2
        obj2.x.d = [4,3,4]
        console.log(obj1)
        console.log(obj2)
    </script>
</body>
</html>